//
//  WmcCombinePhotoTitleView.swift
//  YPWatermarkCamera
//
//  Created by Json on 2023/8/4.
//

import UIKit
import RxRelay

class WmcCombinePhotoTitleView: WmcBaseView {

    private lazy var cancelBtn: UIButton = {
        let button = UIButton()
        button.setTitle("取消", for: .normal)
        button.setTitleColor(UIColor.wmc_black85, for: .normal)
        button.titleLabel?.font = buttonFont
        button.contentHorizontalAlignment = .left
        return button
    }()
    
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = 15.wmc_scaleFont()
        label.textColor = UIColor.wmc_black85
        label.textAlignment = .center
        return label
    }()
    
    private(set) lazy var okBtn: UIButton = {
        let button = UIButton()
        button.setTitle("完成", for: .normal)
        button.setTitleColor(UIColor.wmc_mainTheme, for: .normal)
        button.setTitleColor(UIColor.wmc_grayH12_A0A0A0, for: .disabled)
        button.titleLabel?.font = buttonFont
        button.contentHorizontalAlignment = .right
        return button
    }()
    
    private lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.wmc_lineColor
        return view
    }()
    
    private let buttonFont = 15.wmc_scaleFont(weight: .medium)
    
    var title: String = "" {
        didSet {
            titleLabel.text = title
        }
    }
    
    let okAction: PublishRelay<Void> = .init()
    let cancelAction: PublishRelay<Void> = .init()
    
    
    // MARK: UI
    override func makeUI() {
        super.makeUI()
        let hMargin = 16.0.wmc_autoHor
        let buttonW = 40.0.wmc_autoHor
        let titleHMargin = 8.0.wmc_autoHor
        // cancelBtn
        addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { make in
            make.left.equalTo(hMargin)
            make.top.bottom.equalToSuperview()
            make.width.equalTo(buttonW)
        }
        // okBtn
        addSubview(okBtn)
        okBtn.snp.makeConstraints { make in
            make.right.equalTo(-hMargin)
            make.top.bottom.equalToSuperview()
            make.width.equalTo(buttonW)
        }
        // titleLabel
        addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(cancelBtn.snp.right).offset(titleHMargin)
            make.centerY.equalToSuperview()
            make.right.equalTo(okBtn.snp.left).offset(-titleHMargin)
        }
        // lineView
        addSubview(lineView)
        lineView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(1.0)
        }
    }
    
    // MARK: Bind Action
    override func bindViewAction() {
        super.bindViewAction()
        okBtn.rx.tap.bind(to: okAction).disposed(by: rx.disposeBag)
        cancelBtn.rx.tap.bind(to: cancelAction).disposed(by: rx.disposeBag)
    }

}
